/*
 * User: Jonathan Slenders and Christophe Lambrechts
 * Date: 25/04/2006
 */

using System;
using System.Collections; // voor ArrayList
using System.Reflection;
using Yaml;

namespace Test_Christophe
{
	/// <summary>
	/// Test class that has a Main() method where
	/// object of the TryCode class can be tested
	/// </summary>
	class MainChristophe
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		static void Main(string[] args)
		{
			// TryCode.boxing();
			
			Type t = typeof(Yaml.Binary);
			string s = t.Assembly.FullName.ToString();
			Console.WriteLine("The fully qualified assembly name of Yaml is {0}.", s);
	            
			testYamlNode();
		}

		static private void testYamlNode()
		{
			ArrayList parse = new ArrayList();

			// In this functions is some test data added to a Arraylist of strings
			// Uncomment to test some type
			// Varia(parse);
			// Float(parse);
			 Timestamp(parse);
            // Binary(parse);
			// Null(parse);
			// Boolean(parse);
			// Integer(parse);
			// String(parse);

			// Parse all items in ArrayList, catches ParseException
			foreach(string s in parse)
			{
				Console.WriteLine("Parsed = >>" + s + "<<");
				try 
				{
					Node testNode = Node.Parse(s);
					Console.WriteLine(testNode.ToString());
					Console.WriteLine("Yaml result = " + testNode.Write());
				}
				catch (ParseException e)
				{
					Console.WriteLine("[ERROR]");
					Console.WriteLine(e);
					Console.WriteLine("[/ERROR]");
				}
				Console.WriteLine("--------------------------------------------------");
			}

			
		}

		private static void Varia(ArrayList parse)
		{
			parse.Add("- \"test\"");
		}

		private static void Float(ArrayList parse)
		{
			parse.Add("!!float -.inf"); 
			parse.Add("+.inf");
			parse.Add("+.Inf");
			parse.Add("-.INF"); //this is a problem, without !!float it is interpreted as sequence
			parse.Add("!!float .NaN");
			parse.Add(".nan");
			parse.Add("!!float .NAN");
			parse.Add("10.89");
			parse.Add("19999380.898300090000000000"); // The result is 19999380.8983001, so there is a rounding. Is this bad??
			parse.Add("19999380.89830009"); // Proof that 000 after the 9 doesn't matter
			parse.Add("80.8983000900000000000");
			parse.Add("-80.8983000900000000001"); // No rounding
			parse.Add("20000000000000.0"); // Will fit in an integer, force to put in float
			parse.Add("9223372036854775810"); // Don't fit in an integer, but will fit in float
			parse.Add("!!float 32300.1E-39");
			parse.Add("!!float 32332.1e+39");
			parse.Add("323:20:32.139"); //  ||
			parse.Add("6.8523015e+5");  //  \/
			parse.Add("685.230_15e+03"); // The same number in different notations: http://yaml.org/type/float.html
			parse.Add("685_230.15"); //     /\
			parse.Add("190:20:30.15"); //   ||
		}

		private static void Timestamp(ArrayList parse)
		{
			parse.Add("2001-12-15T02:59:43");
			parse.Add("2001-12-14t21:59:43");
			parse.Add("2001-12-14 21:59:43");
			parse.Add("!!timestamp 2001-12-15		21:59:43");
			// Fault on next item, because of implicit mappings. Must be tested again later.
			parse.Add("!!timestamp 2001-12-15		24:59:43"); //something wrong with 24 hour, can not! For the spec this is right
			parse.Add("2002-12-14");
			parse.Add("2001-12-15T2:59:43");
			parse.Add("2001-12-15T02:59:43.5Z");
			parse.Add("2001-12-15T02:59:43.05Z");
			parse.Add("2001-12-14t21:59:43.10-05:00");
			parse.Add("!!timestamp 2001-12-14 21:59:43.10 -5");
			parse.Add("!!timestamp 2001-12-14 21:59:43.10 -5:10");
			parse.Add("!!timestamp 2001-12-14 21:59:43.3333333333333+5:10");
			parse.Add("2001-12-15 2:59:43.10"); 
		}

		private static void Binary(ArrayList parse)
		{
			parse.Add("!!binary \"R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5" +
				"OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/++" +
				"f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC" +
				"AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=\""); // A little gif arrow
			parse.Add("!!binary \"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW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issLS4vMDEyMzQ1Njc4\n" + 
				"OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3Bx\n" + 
				"cnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmq\n" +
				"q6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj\n" +
				"5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==");
		}

		private static void Null(ArrayList parse)
		{
			parse.Add("");
			parse.Add("~");
			parse.Add("null");
			parse.Add("Null");
			parse.Add("NULL");
			parse.Add("!!null");
			parse.Add("!!null ~");
			//This gives an error, this is right, if tags used then content after it must be correct
			parse.Add("!!null test"); 
		}

		private static void Boolean(ArrayList parse)
		{
			parse.Add("y");
			parse.Add("Y");
			parse.Add("yes");
			parse.Add("Yes");
			parse.Add("YES");
			parse.Add("n");
			parse.Add("N");
			parse.Add("no");
			parse.Add("No");
			parse.Add("NO");
			parse.Add("true");
			parse.Add("True");
			parse.Add("false");
			parse.Add("False");
			parse.Add("FALSE");
			parse.Add("on");
			parse.Add("On");
			parse.Add("ON");
			parse.Add("off");
			parse.Add("Off");
			parse.Add("OFF"); 
		}

		private static void Integer(ArrayList parse)
		{
			parse.Add("!!int -0xA_7f10c");
			parse.Add("+0xA_7f10c");
			parse.Add("123456789");
			parse.Add("200000000:11:50:59");
			parse.Add("-200000000:11:50:59"); //Problem with sequence
			parse.Add("2000000000");
			parse.Add("02472256"); // Octal
			parse.Add("0b1010_0111_0100_1010_1110"); // Binary
			parse.Add("9223372036854775807"); //Max value
			parse.Add("-9223372036854775808"); //Min value, still problem with sequence
			parse.Add("9223372036854775808"); //To large, try to fit float
			parse.Add("!!int 9223372036854775808"); //To large, force in int (gives error)
			parse.Add("2147483647"); //Max value int32
		}

		private static void String(ArrayList parse)
		{
			parse.Add("Test \"te");
			parse.Add("!!str | \n abc \n def");
			parse.Add("\"test that it is possible to use double quotes \\\" ... \"");
			parse.Add("'test a '' quote in single quotes'");
			parse.Add("test: hello");
			parse.Add("':/%.&(*'");
			parse.Add("\"newlines test, \\nfirst\\nsecond\"");
			parse.Add("- test\n" +
				"  hallo");
			parse.Add("key:\n \"String over more then\n one line\"");
			parse.Add("? test: '#:/%.&(*'"); 
		}
	}
}
